package com.project.config;

import com.project.interceptor.CutstomInterceptor;
import com.project.interceptor.ManagerInterceptor;
import com.project.interceptor.SendInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MVCConfig implements WebMvcConfigurer {
    @Autowired
    private CutstomInterceptor cutstomInterceptor;
    @Autowired
    private ManagerInterceptor managerInterceptor;
    @Autowired
    private SendInterceptor sendInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration customReg =  registry.addInterceptor(cutstomInterceptor);
        customReg.addPathPatterns("/custom/**");
        InterceptorRegistration managerReg =  registry.addInterceptor(managerInterceptor);
        managerReg.addPathPatterns("/manager/**");
        InterceptorRegistration sendReg =  registry.addInterceptor(sendInterceptor);
        sendReg.addPathPatterns("/send/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/produtImage/**")
                .addResourceLocations("file:D:/springBootTest/shopProject/productImage/");
    }
}
